import server from '../utils/request.js'

/**
 * 根据业主ID查询业主信息（新版接口）
 * @param {string|number} ownerId 业主ID
 * @returns Promise
 */
export function getOwnerById(ownerId) {
  return server({
    url: `/owner-server/queryOwnerById/${ownerId}`,
    method: 'GET'
  })
}

// 上传图片到 MinIO，file 为 File 或 Blob
export function uploadImg(file) {
  console.log('uploadImg参数:', file, file instanceof Blob);
  const formData = new FormData();
  formData.append('file', file, 'face.jpg');
  return server.post('/owner-server/uploadImg', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

export function addOwner(owner){
  return server({
    url:`/owner-server/addOwner`,
    method:'post',
    data:owner
  })
}

export function getAllBuildings(){
  return server({
    url:`/infrastructure-server/building/all`,
    method:'get'
  })
}

/**
 * Fetches all communities from the server
 * @returns {Promise} A promise that resolves with the community data
 */
export function getCommunity(){
  return server({
    url:`/infrastructure-server/community/all`,
    method:'get'
  })
}